import 'package:flutter/material.dart';

import '../../utils/http.dart';

class HomeList extends StatefulWidget {
  const HomeList({super.key});

  @override
  State<HomeList> createState() => _HomeListState();
}

List notifyList = [
  {
    'title': '中秋、国庆温馨提示中秋、国庆温馨提示',
    'content': '中秋、国庆温馨提示中秋、国庆温馨提示中秋、国庆温馨提示中秋、国庆温馨提示中秋、国庆温馨提示中秋、国庆温馨提示',
    'createdAt': '2024-09-22 15:00:00',
  },
  {
    'title': '中秋、国庆温馨提示中秋、国庆温馨提示',
    'content': '中秋、国庆温馨提示中秋、国庆温馨提示中秋、国庆温馨提示中秋、国庆温馨提示中秋、国庆温馨提示中秋、国庆温馨提示',
    'createdAt': '2024-09-22 15:00:00',
  },
  {
    'title': '中秋、国庆温馨提示中秋、国庆温馨提示',
    'content': '中秋、国庆温馨提示中秋、国庆温馨提示中秋、国庆温馨提示中秋、国庆温馨提示中秋、国庆温馨提示中秋、国庆温馨提示',
    'createdAt': '2024-09-22 15:00:00',
  },
];

class _HomeListState extends State<HomeList> {
  @override
  initState() {
    super.initState();
    getdata();
  }

  getdata() async {
    final res = await http.get('/announcement');
    setState(() {
      notifyList = res['data'];
    });
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Row(
          children: [
            Image.asset(
              'assets/images/notice@2x.png',
              width: 24,
              height: 24,
            ),
            const SizedBox(
              width: 5,
            ),
            const Text(
              '社区',
              style: TextStyle(fontWeight: FontWeight.w700, fontSize: 23),
            ),
            const Text(
              '公告',
              style: TextStyle(
                  fontWeight: FontWeight.w700,
                  color: Colors.amber,
                  fontSize: 23),
            ),
          ],
        ),
        ListView(
            shrinkWrap: true,
            physics: const NeverScrollableScrollPhysics(),
            children: notifyList.map((item) {
              return GestureDetector(
                onTap: () {
                  Navigator.pushNamed(context, '/noticedetail',
                      arguments: item['id']);
                },
                child: Container(
                  // ignore: prefer_const_constructors
                  padding: EdgeInsets.all(10),
                  margin: EdgeInsets.only(top: 10),
                  decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(10)),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(item['title']),
                      SizedBox(height: 10),
                      Text(item['content']),
                      SizedBox(height: 10),
                      Text(item['createdAt'])
                    ],
                  ),
                ),
              );
            }).toList()),
      ],
    );
  }
}
